*ALTERNATIVE DV GENDER

*Print Figure corresponding to .do file title

clear all
use "ESS.dta" 

drop if Ingroup==0
 
*1st alternative variable Gender

drop D_gender 
gen D_gender=(5-wmcpwrk)/4 if Female==0

gen D=D_gender


label var D "Discriminatory attitudes"

 
 global y1 "D"
 global x1 "total_eduyrs"
 global z1 "Age   Edu_mum  i.Country  i.essround"
 global z2 "   Edu_mum i.Country  i.essround"
 global IV "T r"
 global z1b "Age Age2   Edu_mum  i.Country  i.essround"
 global z2b "   Edu_mum i.Country   i.essround"

 
*Discrimination

quietly: reg  $y1   $x1  
est store Correlation
local N1=  e(N)
 
quietly:reg  $y1   $x1  $z1  if Monotonic==1, robust
est store OLS
local N2=  e(N)

 
drop total_eduyrs
gen total_eduyrs=eduyrs
la var total_eduyrs "Years of education"
global x1 "total_eduyrs"


quietly:rdbwselect  $y1  r if Monotonic==1,  covs(Edu_mum   r1 r2 r3 r4 r5 r6 r7 r8  c1 c2 c3 c4 c5 c6 c7 c8 c9   c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 )
local u1 =floor(e(h_mserd))
g  w=max(0,`u1'-abs(r)) 

quietly: ivreg2  $y1  ($x1 = $IV)   $z2 [pweight= w] if Monotonic==1, first  baselevels robust   gmm2s 
est store IV_all
mat l e(first)
local Fm= floor(e(first)[rownumb(e(first),"SWF"),1])
local N3=  e(N)
su  $y1 if e(sample), mean
loc Meanm:di%8.2fc r(mean)
drop w

reg  $y1  r 
su  $y1 if e(sample), mean
loc Mean:di%8.2fc r(mean) 
loc Meanm=trim("`Mean'")
di `Means'

quietly: rdbwselect  $y1  r if Strong==1,  covs(Edu_mum    r1 r2 r3 r4 r5 r6 r7 r8 c1 c2 c3 c4 c5 c6 c7 c8 c9  c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 )
local u2 =floor(e(h_mserd))
g w=max(0,`u2'-abs(r)) 

quietly: ivreg2  $y1  ($x1 = $IV)   $z2  [pweight=w] if Strong==1, first  baselevels robust   gmm2s  
est store IV_restricted
mat l e(first)
local Fs= floor(e(first)[rownumb(e(first),"SWF"),1])
local N4= e(N)
su  $y1 if e(sample), mean
loc Mean:di%8.2fc r(mean)
loc Means=trim("`Mean'")
drop w

	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
	grstyle set color   "180 180 180" "130 130 130" "65 65 65"  "0 0 0" 
    grstyle set graphsize 13cm 11.5cm 	
	coefplot  (Correlation, label( "Correlation" "{it:N}=`N1'") ) (OLS, label("OLS" "{it:N}=`N2'") )   (IV_all, label("IV (all)" "{it:N}=`N3'" ))  (IV_restricted, label ("IV (strong)" "{it:N}=`N4'" ) ) ,     keep( total_eduyrs)   xscale(range(-0.2,0.2)) xlab(-0.2(.05)0.2, grid gstyle(minor))   xline(0,  lpattern(dash)  )   msymbol(d)  levels(95) ciopts(recast(. rcap))  xtitle("Women should forgo paid work for family", size(medsmall))    ylabel(,angle(vertical) labsize(medsmall))  legend(position(12) rows(1) span )  baselevels     title("{bf:Gender attitudes}")  note("OLS, IV(all) and IV(strong) control for gender,maternal education,country and round effects." "Bandwidths in IV strategies are chosen using  MSE-optimal bandwidth selector." "IV(all) specification: 1st stage {it:F}-stat = `Fm' | bandwidth = `u1' | Outcome mean = `Meanm'." "IV(strong) specification: 1st stage {it:F}-stat = `Fs' | bandwidth = `u2' | Outcome mean = `Means'.", size(vsmall) span)
graph export "AppendixB_3c.png", replace 
 

*2nd alternative vadriable Gender

clear all
use "ESS.dta" 

gen  Treat=2-admge 
*1: girls women, 2: boys men
*gen Treat2=2-icsbfm
*replace Treat=Treat2 if Treatment==.

keep if Treat==1

gen Bad_nochildren=5-anvcld
la var Bad_nochildren "Disapprove no children"
 
gen D=Bad_nochildren/4
 
 

*Discrimination
 
 local y1 "D"
 local x1 "total_eduyrs"
 local z1 "Age Age2  Edu_mum i.Country  i.essround"
 local z2 "Edu_mum i.Country  i.essround"

 
*Discrimination

quietly: reg  $y1   $x1  
est store Correlation
local N1=  e(N)

quietly: reg  $y1   $x1  $z1   if Monotonic==1, robust
est store OLS
local N2=  e(N)

drop total_eduyrs
gen total_eduyrs=eduyrs
la var total_eduyrs "Years of education"
global x "total_eduyrs"

quietly: rdbwselect  $y1  r if Monotonic==1,  covs(Edu_mum  r1 r2 r3 r4 r5 r6 r7 r8 c1  c2 c3 c4 c5 c6 c7 c8 c9    c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 )
local u1 =floor(e(h_mserd))
g  w=max(0,`u1'-abs(r)) 

quietly: ivreg2  $y1  ($x1 = $IV)   $z2  [pweight=w]  if Monotonic==1,  first baselevels robust   gmm2s 
est store IV_all
mat l e(first)
local Fm= floor(e(first)[rownumb(e(first),"SWF"),1])
local N3=  e(N)
su  $y1 if e(sample), mean
loc Mean:di%8.2fc r(mean)
loc Meanm=trim("`Mean'")
drop w

quietly: rdbwselect  $y1  r if Strong==1,  covs(Edu_mum   r1 r2 r3 r4 r5 r6 r7 r8 c1  c2 c3 c4 c5 c6 c7 c8 c9   c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 )
local u2 =floor(e(h_mserd)) 
g w=max(0,`u2'-abs(r))


quietly: ivreg2  $y1  ($x1 = $IV)   $z2  [pweight=w] if Strong==1, first baselevels robust   gmm2s 
est store IV_restricted
mat l e(first)
local Fs= floor(e(first)[rownumb(e(first),"SWF"),1])
local N4= e(N)
su  $y1 if e(sample), mean
loc Mean:di%8.2fc r(mean)
loc Means=trim("`Mean'")
drop w


	   grstyle init
	 grstyle set legend 2,  nobox
	 grstyle set size 8pt: tick_label key_label
	 grstyle set size 12pt: heading
	 grstyle set size 10pt: subheading axis_title
	grstyle set color     "180 180 180" "130 130 130" "65 65 65"  "0 0 0" 
	 grstyle set graphsize 13cm 11.5cm
	coefplot  (Correlation, label( "Correlation" "{it:N}=`N1'")  ) (OLS, label("OLS" "{it:N}=`N2'")  )   (IV_all, label("IV (all)" "{it:N}=`N3'" )  )  (IV_restricted, label ("IV (strong)" "{it:N}=`N4'" ) ) ,     keep(total_eduyrs)   xscale(range(-0.2,0.2)) xlab(-0.2(.05)0.2, grid gstyle(minor))   xline(0,  lpattern(dash)  )   msymbol(d)  levels(95) ciopts(recast(. rcap))  xtitle("Disapprove women with no children", size(medsmall))    ylabel(,angle(vertical) labsize(medsmall))  legend(position(12) rows(1) span )  baselevels     title("{bf:Gender attitudes}") note("OLS, IV(all) and IV(strong)  control for maternal education, country and round fixed effects." "Bandwidths in IV strategies are chosen using  MSE-optimal bandwidth selector." "IV(all) specification: 1st stage {it:F}-stat = `Fm' | bandwidth = `u1' | Outcome mean = `Meanm'." "IV(strong) specification: 1st stage {it:F}-stat = `Fs' | bandwidth = `u2' | Outcome mean = `Means'.", size(vsmall) span)
graph export "AppendixB_3d.png", replace 
 
 
 